<?php
/**
 *	九块邮
 *
 */
defined('InShopNC') or exit('Access Invalid!');

class activityControl extends MobileControl{

    public function __construct(){
		parent::__construct();
    }
	
	/**
	 * 单个活动信息页
	 */
	public function indexOp(){
		//根据买家用户信息所在地区展示在相应地区展示的商品-市级-省级
		/*if(isset($_SESSION['is_login']) && (int)$_SESSION['is_login'] == 1){
			$member = Model('member')->infoMember(array('member_id'=>(int)$_SESSION['member_id']));
			$area_info = preg_split('/\t/', $member['member_areainfo'],-1,PREG_SPLIT_NO_EMPTY);
			if(count($area_info)==1){
				$param['show_in_province_ids'] = (int)$member['member_provinceid'];
			}elseif(count($area_info)==2 || count($area_info)==3){
				$param['show_in_city_ids'] = (int)$member['member_cityid'];
			}
		}*/
		$this->show9kyPage($param);
	}
	
	//九块邮板块

	private function show9kyPage($param){

        $model_store_class = new my_goods_classModel ();

        $list_goods_class = $model_store_class->getClassList ( array (
            'store_id' => JKY_STORE_ID
        ) );
        tpl::output('list_goods_class',$list_goods_class);
        
        $goods_class_id = array(0);
        if(is_array($list_goods_class)){
            foreach($list_goods_class as $v){
                $goods_class_id[]=$v['stc_id'];
            }
        }
        $goods_class_str=implode(',',$goods_class_id);

        $where = "";
        if($_GET ['stc_id']){
            $where .= " and scg.stc_id = {$_GET ['stc_id']}";
        }
        if($_GET ['keyword']){
            $where .= " and g.goods_name like '%{$_GET ['keyword']}%'";
        }
        $sql = "select g.store_id,g.goods_id,g.goods_image,g.goods_name,stc_id from #__goods as g left join #__store_class_goods scg on g.goods_id=scg.goods_id where store_id=".JKY_STORE_ID." and goods_show=1 and goods_state=0 and scg.stc_id in ($goods_class_str) $where order by g.goods_sort desc";

        $pageSize = 20;
        $curPage = (int)$_GET['curpage'];

        $rs = Db::PageQuery($sql,$curPage,$pageSize);
        $list = $rs->fetchAll();
        //分页
 
       
        


		$pageSize = 40;
		$param['order'] = '`goods`.goods_sort desc';
		$param['store_id'] = JKY_STORE_ID;
		$param['goods_show'] = '1';
		$param['goods_state'] = '0';
		$param['keyword'] = $_GET['keyword'];	
		$tnum =  count(Model('goods')->getGoods($param,'','goods.*','stc'));
		$param['limit'] = $pageSize ;
		$page	= new Page();
		$page->setEachNum($pageSize );
		$page->setStyle('admin');
		$list	= Model('goods')->getGoods($param,$page,'goods.*','stc');

		$now_time = time();
		$sql = "SELECT * FROM #__adv WHERE ap_id = '373' AND is_allow = '1' AND adv_start_date < $now_time AND adv_end_date > $now_time ORDER BY slide_sort ASC";
		$adv = Db::queryAll($sql);



		//$solon = array(253,257,263,258); //美发系列stc_id IN(396,257,263,258,293,306,337,378,379) AND
		$catSql = 'SELECT stc_id,stc_name,stc_parent_id,stc_state,store_id,stc_type_id FROM `shopnc_store_goods_class` WHERE  `stc_state`=1 AND stc_type_id IN(1,2)';
		$catResult = Db::queryAll($catSql);

		$catList = array();

		foreach($catResult as $val){
			if($val['stc_type_id'] == 1){
				$catList['salon'][] = $val;
			}else{
				$catList['cosmet'][] = $val;
			}
		}

		//var_dump($catResult);
		$this->_assignMobileData($page);
		Tpl::output('list',$list);
		//Tpl::output('totalPage',ceil($tnum/15));
		Tpl::output('catlist',$catList);

		Tpl::output('adv',$adv);
		Tpl::showpage('activity_9ky');
	}
	
}